from PyQt5.QtWidgets import QWidget, QLabel, QVBoxLayout, QComboBox, QMessageBox
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import Qt
import os
import json


class AskWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowIcon(QIcon('assets/Help.ico'))
        self.setWindowTitle('询问')
        self.setWindowFlags(self.windowFlags() & ~Qt.WindowCloseButtonHint)

        self.layout = QVBoxLayout()

        self.tip = QLabel('Please select your preferred language / 请选择你的偏好语言')
        self.tip.setStyleSheet('font-family:"抖音美好体"')
        self.layout.addWidget(self.tip)

        lang_ls = []

        print(-2)
        for root, dirs, files in os.walk('C:\\Users\\zhouyuchen\\Desktop\\工作区\\编程\\PycharmProjects\\摩斯电码翻译器\\src\\assets\\lang', topdown=False):
            print(-1)
            for file in files:
                file_path = os.path.join(root, file)
                print(0)

                with open(file_path, 'r', encoding='utf-8') as file2:
                    print(1)
                    file_content = file2.read()
                    print(2)
                    lang_data = json.loads(file_content)
                    print(3)
                    lang_ls.append(lang_data["langName"])
                    print(4)
                    print(lang_data["langName"])
                    print(file_content)
                    print(file_path)

        self.select = QComboBox()
        self.select.setStyleSheet('font-family:"抖音美好体"')
        for item in lang_ls:
            self.select.addItem(item)

        self.layout.addWidget(self.select)

        self.setLayout(self.layout)

    def exec(self):
        is_quit = super(AskWindow, self).exec_()  # Use exec_() instead of exec
        return is_quit, self.select.currentText()
